/**
 * Copyright (c) 2002-2011 旭鸣信息
 * All rights reserved. 
 * File：SysServerCfgDaoImpl.java
 * History:
 *       May 11, 2012: Initially created, liuzhi.
 */
package com.xteam.ecsystem.dao.Impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;


import com.xteam.ecsystem.dao.ISysServerCfgDao;
import com.xteam.ecsystem.entities.SysServerConfig;
import com.xteam.ecsystem.utils.StringUtil;

/**
 * 服务端配置数据访问实现类
 * @author liuzhi
 * 
 */
@Repository
public class SysServerCfgDaoImpl extends DDLPrefix implements ISysServerCfgDao {
	
	@SuppressWarnings("unchecked")
	@Autowired
	private BaseDaoImpl baseDao;

	@SuppressWarnings("unchecked")
	public SysServerConfig getSysServerCfg() {
		List<SysServerConfig> list = new ArrayList<SysServerConfig>();
		
		try {
			String hql = SQL_FROM + SysServerConfig.REF + SQL_WHERE + "1=1";
			list = this.baseDao.find(hql);
			
			if (!list.isEmpty()) {
				return list.get(0);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}

	public void saveSysServerCfg(SysServerConfig serverCfg){
		try {
			if (StringUtil.isNotNullOrEmpty(serverCfg.getSscId())) {
				this.baseDao.update(serverCfg);
			}else{
				this.baseDao.save(serverCfg);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
